CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

# set project name
PROJECT (anry_stock)

# set default build type
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
	SET (CMAKE_BUILD_TYPE "Release")
ENDIF ()

# get wxWidgets flags
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
	EXECUTE_PROCESS (COMMAND ${CMAKE_CURRENT_BINARY_DIR}/extra/contrib/build/bin/wx-config --cxxflags OUTPUT_VARIABLE WX_CXXFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
	EXECUTE_PROCESS (COMMAND ${CMAKE_CURRENT_BINARY_DIR}/extra/contrib/build/bin/wx-config --cflags OUTPUT_VARIABLE WX_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
	EXECUTE_PROCESS (COMMAND ${CMAKE_CURRENT_BINARY_DIR}/extra/contrib/build/bin/wx-config --libs OUTPUT_VARIABLE WX_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF ()

#################################################################################################
# set C/CXX flags
#################################################################################################
# for release 
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WX_CFLAGS} -O2 -Wall -Wextra -g0")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WX_CXXFLAGS} -O2 -Wall -Wextra -g0")
SET (CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS})
SET (CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS})
# for debug
SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WX_CFLAGS} -O2 -Wall -Wextra -g")
SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WX_CXXFLAGS} -O2 -Wall -Wextra -g")
#################################################################################################
# set linker flags
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
IF (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
	SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")
	SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -s")
	SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
ENDIF ()	
#################################################################################################

# add definitions
ADD_DEFINITIONS ()

# common include directory
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/extra/contrib/build/include/)
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}/anry-stock-library)

# common link directory
LINK_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/extra/contrib/build/lib/)
LINK_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/anry-stock-library)

# add 3rd party library
ADD_SUBDIRECTORY (./extra/contrib)

# add my binary
IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
	ADD_SUBDIRECTORY ("./anry-stock-library")
	ADD_SUBDIRECTORY ("./anry-stock")
ENDIF ()
